//
//  SupermarketDetailViewController.m
//  PeopleStreet
//
//  Created by 刘建峰 on 16/6/28.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "SupermarketDetailViewController.h"

@interface SupermarketDetailViewController ()
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UIScrollView *scroView;
@property (weak, nonatomic) IBOutlet UILabel *supermarketTitle;
@property (weak, nonatomic) IBOutlet UILabel *numberLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *suerpmarketDetail;
@property(nonatomic,strong)NSString * phoneNumber;
@property (weak, nonatomic) IBOutlet UIImageView *superImage;
@property (weak, nonatomic) IBOutlet UILabel *superName;
@property (weak, nonatomic) IBOutlet UIImageView *superLevel;


@end

@implementation SupermarketDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _phoneNumber = @"";
    [self initViewLayout];
    [self getSuperDetail];
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroView];
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 463), NO);
    _superImage.layer.masksToBounds = YES;
    _superImage.layer.cornerRadius = 13*VerticalRatio();
}

- (IBAction)back:(id)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}


#pragma mark === 获取求购详情
- (void)getSuperDetail{
    
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:_superId forKey:@"mmdeId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_queryMallMarketDemandInfo withHttpType:@"POST" withTag:SX_SX_queryMallMarketDemandInfo];
}


#pragma mark  ==  拨号
- (IBAction)callHandel:(id)sender {
    [Common callPhone:_phoneNumber view:self.view];
}

#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag==SX_SX_queryMallMarketDemandInfo) {
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            NSDictionary * dic = database[@"result"][@"demand"];
            _supermarketTitle.text = [NSString stringWithFormat:@"%@",dic[@"mmdeName"]];
            _numberLabel.text = [NSString stringWithFormat:@"需求量%@%@",dic[@"mmdeNum"],dic[@"mmdeLabel"]];
            
            _suerpmarketDetail.frame = flexibleFrame(CGRectMake(14, 114, 296, 32), NO);
            _suerpmarketDetail.numberOfLines = 0;
            _suerpmarketDetail.text = [NSString stringWithFormat:@"%@",dic[@"mmdeContent"]];
            [_suerpmarketDetail sizeToFit];
           
            _phoneNumber = [NSString stringWithFormat:@"%@",dic[@"mmdePhone"]];
            
            
            if (![dic[@"memberUrl"] isEqual:[NSNull null]]) {
                [_superImage sd_setImageWithURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@",dic[@"memberUrl"]]]];
            }
            
            
            if (![dic[@"memberNickName"] isEqual:[NSNull null]]) {
                _superName.text = [NSString stringWithFormat:@"%@",dic[@"memberNickName"]];
            }else{
                _superName.text = [NSString stringWithFormat:@"%@",dic[@"memberLoginName"]];
            }
            
            [_superName sizeToFit];
            _superLevel.frame = CGRectMake(CGRectGetMaxX(_superName.frame)+5, CGRectGetMinY(_superLevel.frame), CGRectGetWidth(_superLevel.frame), CGRectGetHeight(_superLevel.frame));
            [_superLevel sd_setImageWithURL:[NSURL URLWithString:[Common stringFromData:dic[@"memberLevelUrl"]]]];
            
            if ([NSString stringWithFormat:@"%@",dic[@"mmdeCreateTime"] ].length>0) {
               
                _timeLabel.text = [Common updateTimeForData:[NSString stringWithFormat:@"%@",dic[@"mmdeCreateTime"] ]];
            }
            
            
        }
    }
    
}
-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    //
    [self dismissWaitDialog];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
